package com.ketangpai.admin.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ketangpai.admin.dao.UserNoticeDao;
import com.ketangpai.admin.entity.UserNotice;
import com.ketangpai.admin.entity.param.Param;
import com.ketangpai.admin.service.UserNoticeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户通知表(UserNotice)表服务实现类
 *
 * @author makejava
 * @since 2023-06-14 02:07:17
 */
@Service("userNoticeService")
@Transactional
public class UserNoticeServiceImpl extends ServiceImpl<UserNoticeDao, UserNotice> implements UserNoticeService {

    @Resource
    private UserNoticeDao userNoticeDao;

    @Override
    public Map<String, Object> selectList(Param param) {
        Page<UserNotice> page = new Page<>(param.getPage(), param.getPageSize());
        userNoticeDao.selectPage(page, null);
        Map<String, Object> map = new HashMap<>();
        map.put("total", page.getTotal());
        map.put("list", page.getRecords());
        return map;
    }

    @Override
    public List<UserNotice> getAll() {
        return userNoticeDao.selectList(null);
    }

    @Override
    public boolean insert(UserNotice notice) {
        return save(notice);
    }

    @Override
    public boolean update(UserNotice userNotice) {
        return userNoticeDao.updateById(userNotice) > 0;
    }

    @Override
    public boolean modifyBatch() {//一键已读
        List<UserNotice> list = getAll();
        for (UserNotice userNotice : list) {
            userNotice.setStatus(0);
        }
        return updateBatchById(list);
    }

    @Override
    public boolean deleteById(Integer id) {
        return userNoticeDao.deleteById(id) > 0;
    }


}

